<!-- 考生试卷列表 -->
<template>
  <div class="parper">
    <!-- <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="POLIC" name="polic"></el-tab-pane>
      <el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
      <el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
      <el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>
    </el-tabs> -->
    <div class="flex align serarch-sum">
      <div class="parper-title">
        总计：<span style="color: var(--main-color)">{{ total }}人</span>
      </div>
      <div class="serarch flex align">
        <el-input
          placeholder="请输入准考证号查询或姓名查询"
          prefix-icon="el-icon-search"
          v-model="keyword"
          clearable
        >
        </el-input>
        <el-button @click="searchEvent()">查询</el-button>
      </div>
    </div>

    <el-table :data="list" height="67vh" style="width: 95%">
      <el-table-column prop="index" label="序号" width="80"></el-table-column>
      <el-table-column prop="nameK" label="考场名称" width="280">
      </el-table-column>
      <el-table-column prop="subject_name" label="科目" width="150">
      </el-table-column>
      <el-table-column prop="subject_level_name" label="考试级别" width="150">
      </el-table-column>
      <el-table-column prop="name" label="考生" width="140"> </el-table-column>
      <el-table-column prop="exam_type_text" label="考试状态" width="200">
      </el-table-column>
      <el-table-column prop="examinee_number" label="准考证号" width="270">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div class="flex align">
            <el-button
              @click="handleEdit(scope.$index, scope.row)"
              class="btn-item"
              plain
              type="danger"
              >{{
                scope.row.exam_time == 0 && scope.row.status == 2
                  ? "立即考试"
                  : scope.row.status == 3
                  ? "考试结束"
                  : "考试中"
              }}</el-button
            >
            <el-button
              type="danger"
              :disabled="scope.row.disabledCall"
              @click="toCall(scope.$index, scope.row)"
              class="btn-item"
              >叫号</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <div class="page flex align center">
      <div
        class="prev-box flex align center"
        @click="next(0)"
        :style="{ transform: index == 0 ? 'scale(0.9)' : '' }"
      >
        <i class="el-icon-arrow-left font"></i>
      </div>
      <div class="count">
        <span>{{ totalPages == 1 ? totalPages : page }}/</span>{{ totalPages }}
      </div>
      <div
        class="prev-box flex align center"
        @click="next(1)"
        :style="{ transform: index == 1 ? 'scale(0.9)' : '' }"
      >
        <i class="el-icon-arrow-right font"></i>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getSubjectRecordList,
  ExaminerStartExam,
  SubjectProduct,
  callNumber,
} from "@/api/apiData";
import { mapMutations } from "vuex";
import Mixin from "@/mixin/index.js";
export default {
  name: "parper",
  components: {},
  mixins: [Mixin],
  data() {
    return {
      // activeName: "first",
      page: 0,
      totalPages: 1,
      offset: 7,
      list: [],
      total: 0,
      index: -1,
      idx: 1,
      keyword: "",
    };
  },
  computed: {},
  methods: {
    ...mapMutations(["saveImage"]),
    // handleClick(tab, event) {
    //   console.log(tab, event);
    // },
    // 叫号
    toCall(index, data) {
      console.log(data);
      let obj = {
        examinee_number: data.examinee_number,
      };
      this.$message({
        type: "success",
        message: "已叫号~",
      });
      this.list[index].disabledCall = true;
      setTimeout(() => {
        this.list[index].disabledCall = false;
      }, 3000);
      callNumber(obj).then((res) => {
        if (res.code == 1) {}
      });
    },
    // 跳转改卷
    handleEdit(index, data) {
      console.log(data);
      let parpams = {
        subject_id: data.subject_id,
        subject_record_id: data.subject_record_id,
        examinee_number: data.examinee_number,
        subject_name: data.subject_name,
        id_number: data.id_number,
        subject_level_id: data.subject_level_id,
      };
      this.saveImage(data.avatar);
      let that = this;
      let name;
      switch (data.check_type) {
        case 1: //钢琴
          name = "examParperOff";
          break;
        case 2: //听力
          name = "listenerParperOff";
          parpams.exam_video = data.exam_video;
          break;
        case 3: //歌唱
          name = "singerResultOff";
          break;
      }
      console.log(data.exam_time);
      if (data.exam_time == 0 && data.status == 2) {
        this.$confirm(
          "<div style='font-size:16px'><div style='text-align:center;margin-bottom:20px'><img width='120' style='margin:0 auto' src=" +
            data.avatar +
            "></div>该考生为" +
            data.name +
            ", 确定是否继续考试?</div>",
          "提示",
          {
            confirmButtonText: "继续",
            cancelButtonText: "取消",
            dangerouslyUseHTMLString: true,
            cancelButtonClass: "cancelButtonClass",
            confirmButtonClass: "cancelButtonClass",
            type: "warning",
            center: true,
          }
        )
          .then(() => {
            console.log(888);
            // that.$router.push({
            //   name: name,
            //   query: parpams,
            // });
            SubjectProduct({ subject_id: parpams.subject_id }).then((res) => {
              if (res.code == 1) {
                if (res.data.length == 1) {
                  ExaminerStartExam({
                    subject_record_id: data.subject_record_id,
                  }).then((res2) => {
                    if (res2.code == 1) {
                      that.$router.push({
                        name: name,
                        query: parpams,
                      });
                    } else {
                      that.$message({
                        type: "error",
                        message: res2.msg,
                      });
                    }
                  });
                } else {
                  that.$router.push({
                    name: name,
                    query: parpams,
                  });
                }
              } else {
                that.$message({
                  type: "error",
                  message: res.msg,
                });
              }
            });
          })
          .catch(() => {
            that.$message({
              type: "info",
              message: "已取消",
            });
          });
      } else {
        if (data.status == 2) {
          that.$router.push({
            name: name,
            query: parpams,
          });
        } else {
          that.$message({
            type: "warning",
            message: "考试已结束",
          });
        }
      }
    },
    searchEvent() {
      this.page = 0;
      this.totalPages = 1;
      this.list = [];
      this.getList();
    },
    // 获取试卷
    getList() {
      const that = this;
      let { page, offset, totalPages, list, idx } = that;
      let obj = {
        exam_room_id: that.$route.query.id,
        page: idx == 0 ? page - 1 : page + 1,
        offset: offset,
        keyword: that.keyword,
      };
      if (idx == 0) {
        --page;
      }
      if (totalPages > page) {
        getSubjectRecordList(obj).then((res) => {
          // //(res);
          if (res.code == 1) {
            let arr = res.data.list;
            arr.forEach((item, index) => {
              item.index = index + 1;
              item.nameK = that.$route.query.name;
              item.disabledCall = false;
              if (item.exam_time == 0) {
                item.exam_type_text = "未开始";
              } else {
                item.exam_type_text = "已开考";
              }
            });
            that.list = arr;
            that.page = idx == 0 ? page : page + 1;
            that.totalPages = Math.ceil(res.data.total / offset);
            that.total = res.data.total;
          } else {
          }
        });
      } else {
        //  全部加载加载完毕
        this.$message({
          type: "warning",
          message: "已经是最后一页了~",
        });
      }
    },
    // 翻页
    next(val) {
      const that = this;
      const { page } = that;
      that.index = val;
      that.idx = val;
      setTimeout(() => {
        that.index = -1;
      }, 100);

      if (val == 0) {
        if (page == 1) {
          this.$message({
            type: "warning",
            message: "已经是第一页了~",
          });
          return;
        }
      }

      that.getList();
    },
  },
  beforeRouteEnter(to, from, next) {
    // 导航离开当前路由的时候被调用，this可以被访问到
    if (from.name == "pianoResultOff") {
      location.reload();
    }
    next();
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.getList();
    });
  },
};
</script>
<style lang='less' scoped>
.serarch-sum {
  background: white;
}
.serarch {
  width: 80%;
  background: #fff;
  padding: 0 20px;
  /deep/.el-input {
    margin-right: 20px;
    padding-top: 14px;
    padding-bottom: 14px;
  }
  /deep/.el-input__inner {
    background: #f6f9fc;
    border-radius: 30px;
    font-size: 20px;
    border-color: transparent;
  }
  /deep/.el-button {
    background: @main-color;
    color: #fff;
    font-size: 18px;
    border-radius: 30px;
  }
}
.parper {
  padding: 16px 0;
  background: #f6f9fc;
  width: 100%;
  height: 90vh;
  overflow: hidden;
  .parper-title {
    font-size: 28px;
    font-weight: bold;
    color: #1d1b1b;
    padding: 6px 45px;
    background: #fff;
  }
  .el-table {
    margin: 25px auto 0;
  }
  //   表格
  /deep/ .has-gutter .cell {
    color: @main-color;
    font-size: 30px;
    overflow: visible;
    line-height: 1.5;
    background: transparent;
  }
  /deep/.cell {
    text-align: center;
    color: #111;
    font-weight: bold;
    font-size: 28px;
    overflow: visible;
    line-height: 1.5;
  }
  /deep/ .has-gutter .is-leaf {
    background: #f6f9fc !important;
    border: 0;
  }
  /deep/.has-gutter .gutter {
    background: #f6f9fc;
  }

  // /deep/.el-table--scrollable-y .el-table__body-wrapper {
  //   overflow: hidden;
  // }
  // /deep/.el-table--scrollable-y .el-table__body-wrapper::-webkit-scrollbar {
  //   display: none;
  // }
  .btn-item {
    font-size: 26px;
  }
  // page
  .page {
    width: 100%;
    margin-top: 5vh;
    text-align: center;
    .prev-box {
      width: 42px;
      height: 42px;
      border-radius: 50%;
      border: 1px solid @main-color;
      cursor: pointer;
      .font {
        font-size: 30px;
        color: @main-color;
        font-weight: bold;
      }
    }
    .count {
      cursor: default;
      width: 30%;
      font-size: 32px;
      color: @main-color;
      span {
        font-size: 42px;
      }
    }
  }
}
</style>